<?php
/**
 * Created by PhpStorm.
 * User: tao
 * Date: 2016/12/1
 * Time: 上午10:24
 */

namespace Admin\Controller;
use Think\Controller;
class SuperadminController extends CommonController {
    /**
     * 超级管理员的管理界面
     */
    public function index(){
        $this->display();
    }

	/*------------------------显示所有学生信息--------------------*/
	public function showuserapply(){
        $student = M('student');
    	$res =$student->select();
        $this->assign('res',$res);
        $this->display();
    }
    
	/*--------------------------删除学生信息--------------------*/
	public function delstudent(){
		if(IS_AJAX){
            $id =I('post.idcard');
            $map = ['idCard'=>$id];
            $m = D('student');
            $res = $m->where($map)->delete();
            if($res){
                $out = [
                    'status'=>1,
                    'info'=>'删除成功'
                ];
            }else{
                $out = [
                    'status'=>0,
                    'info'=>'删除失败'
                ];
            }
            $this->ajaxReturn($out);
        }
	}
	/*-----------------------修改学生信息-----------------------*/
	public function informationModify($id = 0){
        if(IS_AJAX){
        	$idcard =I('post.idcard');
        	$sutdentnumber =I('post.studentnumber');
        	$dormitorygrade =I('post.dormitorygrade');
        	$dormitory =I('post.dormitory');
        	$report =I('post.report');
        	$address =I('post.address');
        	$sick =I('post.sick');
        	$prove =I('post.prove');
        	$insurance =I('post.insurance');
            $studentid =  I('post.studentid');
            $studentname =  I('post.studentname');
            $studentsex =  I('post.studentsex');
            $forecast =  I('post.forecast');
            $classname = I('post.classname');
            $spename = I('post.spename');
            $data = [
                'idCard' => $idcard,
                'studentNumber' => $sutdentnumber,
                'dormitoryGrade' => $dormitorygrade,
                'dormitory' => $dormitory,
                'report' => $report,
                'address' => $address,
                'sick' => $sick,
                'prove' => $prove,
                'insurance' => $insurance,
                'studentID' => $studentid,
                'studentName' => $studentname,
                'studentSex' => $studentsex,
                'forecast' => $forecast,
                'className' => $classname,
                'speName' => $spename
            ];
            $map  = ['idCard'=>$idcard];
            $m = D('student');
            $res = $m->where($map)->save($data);
            if ($res) {
                $out = [
                    'info' => '修改成功',
                    'status'=>1
                ];
            } else {
                $out = [
                    'info' => '修改失败',
                    'status'=>0
                ];
            }
            $this->ajaxReturn($out);
        }else{
            $m = D('student');
            $s = D('specialty');
            $c = D('class');
            $d = D('dormitory');
            $map = ['idCard'=>$id];
            $res = $m->where($map)->find();
            $spe = $s->select();
            $class = $c->select();
            $dormitory =$d->select();
            $this->assign('res',$res);
            $this->assign('spe',$spe);
            $this->assign('class',$class);
            $this->assign('dormitory',$dormitory);
            $this->display();
        }
    }
    /*----------------------------------------- 班级信息处理 -----------------------------------------*/

	//显示系部信息
	public function showspecialty(){
		$specialty = M('specialty');
    	$res =$specialty->select();
        $this->assign('res',$res);
        $this->display();
	}
	
	
	//删除系部信息
	public function delspe(){
		if(IS_AJAX){
            $id =I('post.id');
            $map = ['id'=>$id];
            $m = D('specialty');
            $res = $m->where($map)->delete();
            if($res){
                $out = [
                    'status'=>1,
                    'info'=>'删除成功'
                ];
            }else{
                $out = [
                    'status'=>0,
                    'info'=>'删除失败'
                ];
            }
            $this->ajaxReturn($out);
        }
	}
	
	
	
	/**------------------------------------------------------------*/


    //显示班级信息
	public function showactivity(){
		$spename =I('get.id');
		$map =array('speNum'=>$spename);
		$class = M('class');
    	$res =$class->where($map)->select();
        $this->assign('res',$res);
        $this->display();
	}
    
    //删除班级信息
	public function delclassnum(){
		if(IS_AJAX){
            $id =I('post.classnum');
            $map = ['classNum'=>$id];
            $m = D('class');
            $res = $m->where($map)->delete();
            if($res){
                $out = [
                    'status'=>1,
                    'info'=>'删除成功'
                ];
            }else{
                $out = [
                    'status'=>0,
                    'info'=>'删除失败'
                ];
            }
            $this->ajaxReturn($out);
        }
	}
	
	//修改班级信息
	public function classsave($id = 0){
        if(IS_AJAX){
        	$classnum =I('post.classnum');
        	$classname =I('post.classname');
        	$classsize =I('post.classsize');
            $data = [
                'className' => $classname,
                'classSize' => $classsize
            ];
            $map  = ['classNum'=>$classnum];
            $m = D('class');
            $class = $m->where($map)->save($data);
            if ($class) {
                $out = [
                    'info' => '修改成功',
                    'status'=>1
                ];
            } else {
                $out = [
                    'info' => '修改失败',
                    'status'=>0
                ];
            }
            $this->ajaxReturn($out);
        }else{
            
            $c = D('class');
            
            $map = ['classNum'=>$id];
            $class = $c->where($map)->find();
            $this->assign('class',$class);
            $this->display();
            
        }
    }
    


}